import Vue from 'vue'
import './plugins/axios'
import App from './App.vue'
import router from './router/index.js'
// import './plugins/element.js'
import './assets/css/global.css'
import './assets/fonts/iconfont.css'
import ZkTable from 'vue-table-with-tree-grid'
// 导入 Nprogress 包对应js和css 进度条
import Nprogress from 'nprogress'
// 导入富文本编辑器
import VueQuillEditor from 'vue-quill-editor'

import axios from 'axios'

// 配置请求的根路径
axios.defaults.baseURL = 'http://192.168.3.2:8888/api/private/v1/'

// 在request 拦截器中 展示进度条 Nprogres.start()
axios.interceptors.request.use(
        config => {
            Nprogress.start()
            config.headers.Authorization = window.sessionStorage.getItem('token')
                // console.log(config)
            return config
        },
        error => {
            // Do something with request error
            return Promise.reject(error)
        }
    )
    // 在 response 拦截器中，隐藏进度条 Nprogres.done()

axios.interceptors.response.use(config => {
    Nprogress.done()
    return config
})
Vue.prototype.$http = axios

Vue.config.productionTip = false
Vue.component(ZkTable.name, ZkTable)
    // 将富文本编辑器,注册为全局可用的组件
Vue.use(VueQuillEditor)

Vue.filter('dateFormat', function(ariginVal) {
    let len = (ariginVal + '').length //隐式转换为字符串并拿到该字符串的长度;
    let data = '' //定义一个空字符串
    if (len == 10) { //当我传的实参===> 时间戳位数等于10时,单位是秒,我需要乘以1000变为毫秒
        data = ariginVal * 1000
    } else { //否则时间戳位数为13时,单位是毫秒,无需变换
        data = ariginVal
    }

    const dt = new Date(data)
    const y = dt.getFullYear()
    const m = (dt.getMonth() + 1 + '').padStart(2, '0')
    const d = (dt.getDate() + '').padStart(2, '0')
    const hh = (dt.getHours() + '').padStart(2, '0')
    const mm = (dt.getMinutes() + '').padStart(2, '0')
    const ss = (dt.getSeconds() + '').padStart(2, '0')
    return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
})

new Vue({
    router,
    render: h => h(App)
}).$mount('#app')